import React, { PureComponent } from "react";
import { Howl } from 'howler';
import QRCode from 'qrcode.react';
import { HttpClient } from '../../commoe/HttpClient';
import {
  Footer,
  Header,
  Arwes,
  Image,
  Words,
  Frame,
  Table,
  Button,
  Project,
  Row,
  Col,
  Link
} from "arwes";
export default class xinsenlin extends PureComponent {
  constructor(props) {
    super(props);
    this.qrtypemap = {
      1: '1',
      2: '2',
      3: '箱码',
      4: '4',
      5: '5',
      6: '瓶码',
      7: '盒码',
      8: '盒码',
    }
    this.sounds = {
      click: new Howl({
        src: ['./sound/click.mp3']
      }),
      typing: new Howl({
        src: ['./sound/typing.mp3']
      }),
      deploy: new Howl({
        src: ['./sound/deploy.mp3']
      }),
    }
    this.state = {
      show: false,
      list: [],
      filelist: [],
      qrcodelist: [],
      count: 1,
      filename: 0,
    };
  }
  componentDidMount() {
    this.setState({
      show: true
    })
  }
  showfile = (i) => {
    const datalist = this.state.filelist
    datalist[i].show = !datalist[i].show
    this.setState({
      filelist: datalist
    })
    this.forceUpdate();
  }
  removefile = (i) => {
    this.state.filelist.splice(i,1)
    this.forceUpdate();
  }
  getqrcode = () => {
    const response = HttpClient.query('https://test-management.new-forest.cn/bush/v1/label/CreateLabel?sku_id='+this.state.filename+'&count=' + this.state.count, 'get')
    response().then(res => {
      if(res.code!=0){
        alert(res.errormessage)
      }else{
        const newlist = this.state.list
        this.setState({
          list: res.data.concat(newlist)
        })
      }
    })
  }
  gohome = (url) => {
    if (this.props.location.pathname == url) {
      return
    }
    this.sounds.click.play()
    this.sounds.deploy.play()
    this.setState({
      show: !this.state.show
    });
    setTimeout(() => {
      this.props.history.push(url);
    }, 500);
  }
  zhihui = (number) => {
    this.state.list[number].isoperation = !this.state.list[number].isoperation
    this.forceUpdate();
  }
  render() {
    const iconmap = {
      3: (<i className='mdi mdi-package-variant' />),
      6: (<i className='mdi mdi-bottle-soda' />),
      7: (<i className='mdi mdi-cube' />),
      8: (<i className='mdi mdi-cube' />),
    }
    const qrcode = this.state.list.map((option, number) => (
      <Project
        style={{ marginTop: 20 }}
        show={true}
        animate
        headerSize='h3'
        onClick={() => { this.zhihui(number) }}
        icon={<div>{iconmap[option.typenum]}&nbsp;{option.type}</div>}
        header={option.name}
      >
        {anim => (
          <div style={{background:'rgba(255,255,255,0.8)',backgroundColor:'rgba(255,255,255,0.8)'}}>
          <p>
                <Row nested noMargin>
                  <Col s={6} style={{ fontSize: 17, color: option.isoperation ? '#999999' : '#acf9fb' }}>
                    <div style={{ margin: 20 ,color:'black'}}>
                      标签id:{option.id}<br />
                      skuId：{option.sku_id}<br />
                      uuid：{option.uuid}<br />
                    </div>
                  </Col>
                  <Col s={6}>
                    <QRCode
                      id="qrCode"
                      value={option.id}
                      size={200} // 二维码的大小
                      bgColor={option.isoperation ? '#999999' : 'white'}
                      fgColor="#000000" // 二维码的颜色
                      style={{ margin: 'auto', marginLeft: 100, border: '1px solid ' + (option.isoperation ? '#999999' : '#26dafd') }}
                    /></Col>
                </Row>
              </p>
              <p style={{ marginTop: 20, color: option.isoperation ? '#999999' : '#acf9fb' }}>
                <i className='mdi mdi-qrcode' style={{margin: 20,color:'black'}}/>&nbsp;&nbsp;
                <Words animate show={anim.entered} layer='control' style={{ fontSize: 18, fontFamily: '站酷文艺体',color:'black' }}>
                  {option.id+(option.isoperation?'的标签已经扫过了':'的标签还未扫过')}
                </Words>
              </p>
        </div>
        )}
      </Project>
    ))
    return (
      <Arwes
        timeout={1500}
        animate
        show={this.state.show}
        background="./img/background-large.jpg"
        pattern="./img/glow.png"
        style={{ height: '100%' }}
      >
        <div style={{ height: '100%', display: 'flex', flexDirection: 'column' }}>
          <Header animate show={this.state.show}>
            <div style={{
              margin: '0 auto',
              maxWidth: 800,
              padding: '20px 0',
              textAlign: 'left',
              position: 'relative'
            }}>
              <a style={{
                textAlign: 'left',
                width: '50%',
                float: 'left',
                padding: '0 10px',
                display: 'inline-block'
              }}>
                <Image
                  show={this.state.show}
                  onClick={() => this.gohome('/')}
                  layer={"header"}
                  animate
                  resources='./img/mine.jpeg'
                  style={{ width: 45, height: 45, margin: 0, display: 'inline-block' }}></Image>
                <Words
                  onClick={() => this.gohome('/')}
                  animate
                  show={this.state.show}
                  style={{
                    display: 'inline-block',
                    fontSize: 28,
                    color: '#a1ecfb',
                    fontFamily: 'Electrolize, sans-serif',
                    textShadow: '0 0 4px',
                    fontWeight: 'bold',
                    textTransform: 'uppercase',
                    margin: '0 0 0 10px',
                    paddingTop: 4,
                    lineHeight: 1,
                    verticalAlign: 'middle'
                  }}>
                  GUO WÉNJUN
                </Words>
              </a>
              <div style={{ textAlign: 'right', width: '50%', float: 'right', padding: '0 10px', marginLeft: 'auto' }}>
                <Link onClick={() => this.gohome('/blog')} style={{ fontFamily: "Electrolize,sans-serif", lineHeight: '45px' }}><i className="mdi mdi-note-outline" /> Blog</Link>
                <Link onClick={() => this.gohome('/paper')} style={{ marginLeft: 20, lineHeight: '45px' }}><i className="mdi mdi-box-cutter" /> Paper</Link>
                <Link onClick={() => this.gohome('/tools')} style={{ marginLeft: 20, lineHeight: '45px' }}><i className="mdi mdi-calculator" /> Tools</Link>
              </div>
              <div style={{ clear: 'both' }}></div>
            </div>
          </Header>
          <div
            style={{
              flex: '1',
              padding: '20px 0',
              overflowY: 'auto',
            }}
          >
            <div
              style={{
                margin: '0 auto',
                maxWidth: 800,
                marginBottom: 0,
              }}
            >
              <input
                id="getfile"
                ref="getfile"
                type="file"
                style={{ display: "none" }}
              />
              <div style={{ fontSize: 24 }}>
                <Link show={this.state.show} >
                  <i className="mdi mdi-chevron-double-right" />
                  <Words show={this.state.show} animate style={{ marginLeft: 5 }}>新森林测试用二维码工具</Words>
                </Link>

                <Link style={{ float: 'right' }} show={this.state.show} >
                  <i className="mdi mdi-chevron-double-left" />
                </Link>
              </div>
              <Frame
                style={{ marginTop: 20, padding: '10px' }}>
                <Table
                  animate
                  headers={['skuId','数量', '操作']}
                  dataset={[[(<input style={{ backgroundColor: 'rgba(100,100,100,0)', borderColor: 'rgba(172,249,251,0.65)', color: 'rgba(172,249,251,0.65)' }} value={this.state.filename} onChange={e => { this.setState({ filename: e.target.value }) }} />),(<input style={{ backgroundColor: 'rgba(100,100,100,0)', borderColor: 'rgba(172,249,251,0.65)', color: 'rgba(172,249,251,0.65)' }} value={this.state.count} onChange={e => { this.setState({ count: e.target.value }) }} />), (<a onClick={e=>{this.getqrcode()}}>生成码</a>)]]}
                />
              </Frame>
              {qrcode}
            </div>
          </div>
          <Footer animate show={this.state.show} style={{ textAlign: 'left' }}>
            <div style={{
              margin: '0 auto',
              maxWidth: 800,
              padding: '20px 0',
              textAlign: 'left',
              position: 'relative'
            }}>
              <Link href='https://gitee.com/mimidegongkai' target="_blank">
                <i className="mdi mdi-code-brackets" />
                <Words show={this.state.show} animate style={{ marginLeft: 5 }}>Codebase</Words>
              </Link>

              <Link style={{ float: 'right' }} href='http://beian.miit.gov.cn/' target="_blank">
                <Words show={this.state.show} animate style={{ marginLeft: 5 }}>京ICP备2021006930号</Words>
              </Link>
              <div style={{ clear: 'both' }}></div>
            </div>
          </Footer>
        </div>
      </Arwes >
    );
  }
}
